/*
 * sysmo 服务器已被加入监控列表的未连接客户端（节点）信息
 * Copyright (C) 2009  YuLicheng
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sysmo.server.node;

import java.util.List;
import java.util.Vector;
import org.sysmo.db.DatabaseInterface;
import org.sysmo.db.DbItem;
import org.sysmo.server.node.item.Item;
import org.sysmo.server.util.InstanceNotInitializedException;

/**
 * 
 * 监控列表中已存在但未连接的客户端。此类节点不支持在线配置监控项。
 *
 * @author YuLicheng
 */
public class UnconnectedNode extends AddedNode {

    /**
     * 创建未连接节点实例。
     *
     * @param stateListener 节点状态改变回调接口。
     * @param dbInterface 数据库存储接口。
     * @param nodeID 节点ID。
     * @throws NodeNotExistsException 指定ID不存在。
     */
    public UnconnectedNode(NodeStateChangeListener stateListener, 
            DatabaseInterface dbInterface, int nodeID)
            throws NodeNotExistsException {
        super(stateListener, dbInterface, nodeID);
    }

    /**
     * 返回是否与客户端连接，此类总返回false。
     *
     * @return false。
     */
    @Override
    public boolean isConnected() {
        return false;
    }

    /**
     * 获得此节点中的所有监控项对象列表。此类返回的列表中的元素是监控值对应的
     * {@link Item}对象实例。
     *
     * @return 此节点中的所有监控项的{@link Item}实例组成的列表。
     */
    @Override
    public List<Item> getAllItems() {
        if (node == null) {
            throw new InstanceNotInitializedException();
        }
        Vector<Item> allItems = new Vector<Item>();
        try {
            Vector<DbItem> items = dbInterface.query_ItemTableOfClient(node.cid);
            for (DbItem item : items) {
                try {
                    allItems.add(new Item(dbInterface, item.iid));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return allItems;
    }
}
